var a = getApp();

Page({
    data: {
        active: 1,
        tabsList: [ {
            value: 1,
            name: "收益记录"
        }, {
            value: 2,
            name: "我的团队"
        }, {
            value: 3,
            name: "帮扶记录"
        } ],
        reward_type_array: [],
        rewardType: "",
        popupShow: !1,
        detailList: [],
        listData: [],
        page: 1,
        finished: !1,
        total: "",
        isShowDirect: !1,
        subsidyData: null
    },
    onLoad: function(a) {
        this.getEntranceData();
    },
    onReady: function() {},
    onShow: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.getIncomeRecordsData();
    },
    getEntranceData: function() {
        var t = this;
        a._getNetWork({
            url: a.getNetAddresss("plugin.link-move.frontend.home.index"),
            data: {},
            success: function(a) {
                var e = a.data;
                if (e.result) {
                    var i = t.data.tabsList;
                    e.data.star_subsidy_disable || i.push({
                        value: 4,
                        name: "".concat(e.data.boss_subsidy_name, "升级记录")
                    }), t.setData({
                        allData: e.data,
                        reward_type_array: e.data.reward_type_array,
                        rewardType: e.data.reward_type_array[0].value,
                        tabsList: i
                    }), wx.setNavigationBarTitle({
                        title: e.data.plugin_name
                    }), t.getIncomeRecordsData();
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getIncomeRecordsData: function() {
        var t = this;
        if (!this.data.finished) {
            var e = {}, i = "";
            1 == this.data.active ? (i = "plugin.link-move.frontend.home.get-reward", e = {
                page: this.data.page,
                reward_type: this.data.rewardType
            }) : 2 == this.data.active ? (i = "plugin.link-move.frontend.home.my-team", e = {
                page: this.data.page
            }) : 3 == this.data.active ? (i = "plugin.link-move.frontend.home.help-task", e = {
                page: this.data.page
            }) : 4 == this.data.active && (i = "plugin.link-move.frontend.home.star-subsidy", 
            e = {}), a._getNetWork({
                url: a.getNetAddresss(i),
                data: e,
                success: function(a) {
                    if (1 !== a.data.result) return wx.showToast({
                        title: a.data.msg
                    }), !1;
                    if (4 != t.data.active) {
                        var e, i = a.data.data, s = !1;
                        (0 === i.data.length || i.data.length < i.per_page || i.current_page === i.last_page) && (s = !0), 
                        e = t.data.listData.concat(i.data), t.setData({
                            finished: s,
                            listData: e,
                            page: ++t.data.page,
                            total: i.total,
                            isShowDirect: !0
                        });
                    } else {
                        var n = a.data.data;
                        t.setData({
                            subsidyData: n
                        });
                    }
                }
            });
        }
    },
    getHelpData: function() {},
    changeTab: function(a) {
        this.setData({
            active: a.detail.name,
            page: 1,
            finished: !1,
            listData: [],
            isShowDirect: !1
        }), this.getIncomeRecordsData();
    },
    rewardEvent: function(a) {
        this.setData({
            rewardType: a.currentTarget.dataset.item.value,
            page: 1,
            finished: !1,
            listData: []
        }), this.getIncomeRecordsData();
    },
    onClose: function() {
        this.setData({
            popupShow: !1
        });
    },
    showPopup: function(t) {
        var e = this;
        a._getNetWork({
            url: a.getNetAddresss("plugin.link-move.frontend.home.help-detail"),
            data: {
                thaw_id: t.currentTarget.dataset.id
            },
            success: function(a) {
                var t = a.data;
                t.result ? e.setData({
                    popupShow: !0,
                    detailList: t.data
                }) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    }
});